//package com.hsyt.pms.controller.system;
//
//import com.alibaba.dubbo.config.annotation.Reference;
//import com.hsyt.pfc.support.util.LoggerUtil;
//import com.hsyt.pms.api.common.ResultMessage;
//import com.hsyt.pms.api.dto.system.SysUserDto;
//import com.hsyt.pms.api.entity.system.SysUser;
//import com.hsyt.pms.api.enums.Status;
//import com.hsyt.pms.api.vo.system.SysUserVo;
//import com.hsyt.pms.controller.base.BaseController;
//import com.hsyt.pms.sys.dubbo.SysFunctionService;
//import com.hsyt.pms.sys.dubbo.SysUserService;
//import org.apache.commons.collections.CollectionUtils;
//import org.apache.commons.lang.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.ui.ModelMap;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.ServletOutputStream;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.List;
//
///**
// * @ClassName: SysLoginController
// * @Description: 登录服务控制层
// * @author: wangze@hsyuntai.com
// * @date: 2019/1/29 18:19
// */
//@RestController
//@RequestMapping
//public class SysLoginController extends BaseController {
//
//	private static final Logger LOGGER = LoggerFactory.getLogger(SysLoginController.class);
//
//	@Reference(group = "pmsSystem", registry = "pms", version = "0.0.1")
//	private SysFunctionService sysFunctionService;
//
//	@Reference(group = "pmsSystem", registry = "pms", version = "0.0.1")
//	private SysUserService sysUserService;
//
//	@RequestMapping("/login/page")
//	@ResponseBody
//	public ModelAndView page(HttpServletRequest request, HttpServletResponse response) {
//		return new ModelAndView("/system/login");
//	}
//
//	@RequestMapping(value = "/login", method = RequestMethod.GET)
//	public ModelAndView index(ModelMap model) throws Exception {
//		return new ModelAndView("/system/login");
//	}
//
//	@RequestMapping(value = "/changePwdWin", method = RequestMethod.GET)
//	public String changePwdWin(ModelMap model) {
//		return "system/win/changePwd";
//	}
//
//	@RequestMapping(value = "/changePwd")
//	public @ResponseBody
//    ResultMessage changePwd(HttpServletRequest request, @RequestParam("password") String password,
//                            @RequestParam("oldPassword") String oldPassword) {
//		ResultMessage result = new ResultMessage(true, "操作成功");
//		if (StringUtils.isBlank(password) || StringUtils.isBlank(oldPassword)) {
//			result.change(false, "密码为空");
//			return result;
//		}
//		if (!oldPassword.equals("")) {
//			result.change(false, "原密码不正确，请重新输入");
//			return result;
//		}
//		SysUserDto po = new SysUserDto();
//		po.setPassword(password);
//		try {
//			sysUserService.updateUserByKeySelective(po);
//		} catch (Exception e) {
//			result.change(false, "操作失败");
//			LoggerUtil.error(LOGGER, "login-changePwd error: {0}", e.getMessage());
//		}
//		return result;
//	}
//
//	@RequestMapping(value = "/loginOut")
//	public ModelAndView logout(HttpServletRequest request) {
//		request.getSession().invalidate();
//		return new ModelAndView("system/login");
//	}
//
//	@RequestMapping(value = "/console")
//	public ModelAndView page() {
//		return new ModelAndView("system/console");
//	}
//
//	@RequestMapping(value = "/loginTimeout")
//	public ModelAndView adminTimeOut() {
//		return new ModelAndView("common/loginTimeout");
//	}
//
//	@RequestMapping(value = "/loginPermission")
//	public ModelAndView loginPermission() {
//		return new ModelAndView("common/loginPermission");
//	}
//
//	@RequestMapping(value = "/loginVcode", method = RequestMethod.GET)
//	@ResponseBody
//	public ModelAndView loadImg(HttpServletRequest request, HttpServletResponse response) {
//		response.setHeader("Pragma", "no-cache");
//		response.setHeader("Cache-Control", "no-cache");
//		response.setDateHeader("Expires", 0);
//		response.setContentType("image/jpeg");
//		try {
//			ServletOutputStream sos = response.getOutputStream();
//			sos.close();
//		} catch (IOException e) {
//			LoggerUtil.error(LOGGER, "loginVcode-loadImg error: {0}", e.getMessage());
//		}
//		return null;
//	}
//
//	@RequestMapping(value = "/loginIn")
//	@ResponseBody
//	public ResultMessage login(HttpServletRequest request, @RequestBody SysUserDto admin) {
//		ResultMessage result = new ResultMessage(true, "成功");
//		try {
//			String loginName = admin.getUserName();
//			String pwd = admin.getPassword();
//			String vcode = admin.getVcode();
//			if (checkParam(request, result, loginName, pwd, vcode)) {
//				return result;
//			}
//			List<SysUserVo> dbAdmins = sysUserService.listYunAdmin(admin);
//			if (!checkAdminList(dbAdmins, result)) {
//				return result;
//			}
//			SysUser dbAdmin = dbAdmins.get(0);
//			if (!checkAdminStates(dbAdmin.getStatus(), result)) {
//				return result;
//			}
//			if (!pwd.equals(dbAdmin.getPassword())) {
//				result.change(false, "密码不正确");
//				return result;
//			}
//		} catch (Exception e) {
//			result.change(false, "登录异常");
//			LoggerUtil.error(LOGGER, "login-loginIn error: {0}", e.getMessage());
//			return result;
//		}
//		return result;
//	}
//
//	private boolean checkAdminList(List<SysUserVo> list, ResultMessage result) {
//		if (CollectionUtils.isEmpty(list)) {
//			result.change(false, "账号不存在");
//			return false;
//		}
//		if (list.size() > 1) {
//			result.change(false, "存在重复账号");
//			return false;
//		}
//		return true;
//	}
//
//	private boolean checkAdminStates(Integer isBlock, ResultMessage result) {
//		if (Status.FREEZE.getCode().equals(isBlock)) {
//			result.change(false, "账号处于锁定状态");
//			return false;
//		} else if (Status.REVOKE.getCode().equals(isBlock)) {
//			result.change(false, "账号处于锁定状态");
//			return false;
//		}
//		return true;
//	}
//
//	private boolean checkParam(HttpServletRequest request, ResultMessage result, String loginName, String pwd,
//			String vcode) {
//		if (StringUtils.isEmpty(loginName) || StringUtils.isEmpty(pwd) || StringUtils.isEmpty(vcode)) {
//			result.change(false, "登陆信息不全");
//			return true;
//		}
//		return false;
//	}
//
//
//}
